//
//  LZBaseTableViewController.swift
//  Weibo
//
//  Created by lzing on 16/3/20.
//  Copyright © 2016年 lzing. All rights reserved.
//

import UIKit

class LZBaseTableViewController: UITableViewController {

    // 保存用户登录状态
    var userLogin = LZUserAccountViewModel.sharedUserAccountViewModel.userLoginStatus
    
    override func loadView() {
        userLogin ? super.loadView() : setupVisitor()
    }
    
    // 加载登录界面
    private func setupVisitor() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterBtnDidClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginBtnDidClick")
        // 初始化未登录界面
        let customView = LZVisitorView()
        // 设置代理
        customView.delegate = self
        // 判断类型,改变view的背景
        if(self is LZHomeViewController) {
            customView.addAnimation()
        } else if (self is LZMessageViewController ) {
            customView.changeVistorViewIsHome(false, imageName: "visitordiscover_image_message", title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if (self is LZDiscoverViewController) {
            customView.changeVistorViewIsHome(false, imageName: "visitordiscover_image_message", title: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if (self is LZProfileViewController) {
            customView.changeVistorViewIsHome(false, imageName: "visitordiscover_image_profile", title: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        view = customView
    }
}


extension LZBaseTableViewController : LZVisitorViewDelegate {
    func visitorViewLoginBtnDidClick() {
        let oauthVC = LZOauthController()
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    
    // 点击注册按钮modal出注册控制器
    func visitorViewRegisterBtnDidClick() {
        let oauthVC = LZOauthController()
        
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}
